﻿using System;
using System.Text;
using System.IO;
using System.Configuration;
//为命名空间定义别名 "ElseName"
//using ElseName = This.Is.Very.Very.Long.NamespaceName;
//为类定义定义别名
//using ElseCName = This.Is.Very.Very.Long.NamespaceName.ThisIsVeryVeryLongClassName;
namespace _01.hello_inconsole {
  class Program {
    static void Main(string[] args) {
      //SoutHello();
      //useWeek();
      //useVar();
      //useObject();
      //useString();
      //useUnicode();
      //useStringBuilder();
      //useStudent();
      //useConvert();
      //isCanNull();
      //useIf();
      //useFor();
      useUseing();


    }
    /// <summary>
    /// output tring to text file;
    /// </summary>
    static void useUseing() {
      string str = "litong";
      Byte[] bytesToWrite = Encoding.Default.GetBytes(str);
      //创建文件
      using (FileStream fs = new FileStream("litng123.txt", FileMode.Create)) {
        fs.Write(bytesToWrite, 0, bytesToWrite.Length);
      }
      Console.ReadLine();
    }
    /// <summary>
    /// 输出hello
    /// </summary>
    static void SoutHello() {
      Console.WriteLine("hello");
      Console.ReadLine();
    }
    static void dimVariables() {
      int a = 10;
    }
    /// <summary>
    /// 使用person
    /// </summary>
    static void usePerson() {
      Person p = new Person();
      p.age = 10;
      Console.WriteLine(p.age);
      Console.ReadLine();
    }
    /// <summary>
    /// 使用枚举
    /// </summary>
    static void useWeek() {
      Console.WriteLine(Days.Monday);
      Console.ReadLine();
    }
    /// <summary>
    /// 使用var声明变量
    /// </summary>
    static void useVar() {
      var i = 10;
      Console.WriteLine(i);
      Console.ReadLine();
    }
    /// <summary>
    /// 使用Object
    /// </summary>
    static void useObject() {
      Object o1 = new Object();
      Console.WriteLine(o1.GetType());//==>System.Object
      Console.WriteLine(o1.ToString());//==>System.Object
      Console.ReadLine();
    }
    /// <summary>
    /// 使用字符串
    /// </summary>
    static void useString() {
      string s0 = "li";
      string s1 = "li";
      Console.WriteLine(s0);
      Console.WriteLine(s1);
      Console.WriteLine(s0 == s1);//比较内容
      Console.WriteLine((object)s0 == (object)s1);//比较地址
      //字符串实际上是字符数组
      Console.WriteLine(s0[0]);
      Console.ReadLine();
    }
    /// <summary>
    /// 使用unicode字符
    /// </summary>
    static void useUnicode() {
      string u0 = "\\\u0066";
      string u1 = "\\u0066";
      Console.WriteLine(u0 + "," + u1);
      // 取消字符转义
      string s0 = @"d:\Program Files\Visual Studio";
      Console.WriteLine(s0);
      Console.ReadLine();
    }
    /// <summary>
    /// 使用StringBuiler
    /// </summary>
    static void useStringBuilder() {
      StringBuilder strBui = new StringBuilder();
      string s0 = "litong";
      strBui.Append(s0);
      Console.WriteLine(strBui);
      Console.ReadLine();
    }
    /// <summary>
    /// 使用学生类
    /// </summary>
    static void useStudent() {
      Student s = new Student();
      s.age = 10;
      Console.WriteLine(s.age);
      Console.ReadLine();
    }
    /// <summary>
    /// 类型转换
    /// </summary>
    static void useConvert() {
      //int==>string
      int i = 10;
      string s0 = i + "";
      //string == int
      string s1 = "10";
      int i1 = Convert.ToInt32(s1);
      int i2 = Int32.Parse(s1);
      int i3;
      Int32.TryParse(s1, out i3);
      Console.WriteLine(s1 + "," + i1 + "," + i2 + "," + i3);
      Console.ReadLine();

    }
    /// <summary>
    /// 装箱
    /// </summary>
    static void boixing() {
      //装箱:是一种隐世转换
      int i = 100;
      object obj = i;
      int i1 = (int)obj;
    }
    /// <summary>
    /// 值类型可为空
    /// </summary>
    static void isCanNull() {
      //声明一个可为空的int
      int? iNull1 = 100;
      System.Nullable<int> iNull2 = 100;
      //Console.WriteLine(iNull1.Value); // 注意大小写
      //Console.WriteLine(iNull2.value);//System.Nullable<int>.value不可访问,因为它受保护级别限制
      //Console.WriteLine(iNull2.GetValueOrDefault);
      //可为空并不是可以赋于空值,
      int? iNull3 = null;
      //Console.WriteLine(iNull3.Value);//InvalidOperatationException
      //但是支持判读是否为空值,为空时返回false,如果为false就不去获取value的值
      Console.WriteLine(iNull3.HasValue);
      //有值时获取值,没有值时获取默认值
      Console.WriteLine(iNull3.GetValueOrDefault());
      //双问号 ??,如果i的值不为空,这i的值等于 iNull3,如果i的值为空,则i的值时100
      int i = iNull2 ?? 200;
      Console.WriteLine(i);
      Console.ReadLine();
    }
    static void useIf() {
      #region if Contion
      int i1 = 60;
      if (i1 < 60) {
        Console.WriteLine("不及格");
      } else if (i1 >= 60 && i1 < 80) {
        Console.WriteLine("及格");
      } else if (i1 >= 80 && i1 < 100) {
        Console.WriteLine("良好");
      } else if (i1 == 100) {
        Console.WriteLine("满分");
      }
      #endregion
      Console.ReadLine();
    }
    static void useFor() {
      for (int i = 1; i < 10; i++) {
        Console.WriteLine(i);
      }
      Console.ReadLine();
    }
    /// <summary>
    /// ConfigurationManager getkey
    /// </summary>
    static void getKey() {
      ConfigurationManager.AppSettings.Get("");
    }
  }

  /// <summary>
  /// 定义struct
  /// </summary>
  struct Person {
    public int age;
    public string name;
  }
  /// <summary>
  /// 定义enum
  /// </summary>
  enum Days {
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
  }

  class Student {
    public int age {
      get {
        return age + 10;
      }
      set {
        age = value;
      }
    }
  }
  interface Super {
    int i();
  }
  class ISuper : Super {
    public int i() {
      return 5;
    }
  }
}
